package com.sumer.psychology.photo.infrastructure.messaging.rabbitmq;

import com.sumer.psychology.common.port.adapter.messaging.Exchanges;
import com.sumer.psychology.common.port.adapter.messaging.rabbitmq.ExchangeListener;
import com.sumer.psychology.photo.infrastructure.persistence.mongo.MongoPhotoRepository;

/**
 * 照片改变监听
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/10/29
 * Time: 15:58
 */
public class PhotoChangedEventListener extends ExchangeListener {
    private static final String CHANGE_TYPE = "com.sumer.psychology.photo.domain.model.PhotoChangedEvent";
    private MongoPhotoRepository mongoPhotoRepository;

    public PhotoChangedEventListener(MongoPhotoRepository mongoPhotoRepository) {
        this.mongoPhotoRepository = mongoPhotoRepository;
    }

    @Override
    protected String exchangeName() {
        return Exchanges.DEFAULT_EXCHANGE_NAME;
    }

    @Override
    protected void filteredDispatch(String aType, String aTextMessage) {
        mongoPhotoRepository().change(aTextMessage);
    }

    @Override
    protected String[] listensTo() {
        return new String[]{"com.sumer.psychology.photo.domain.model.PhotoChangedEvent"};
    }

    private MongoPhotoRepository mongoPhotoRepository() {
        return mongoPhotoRepository;
    }
}
